package api_day11;

public class StartDemo {
    public static void main(String[] args) {
        /*//继承方式创建线程
        ThreadDemo t1 = new ThreadDemo();
        ThreadDemo t2 = new ThreadDemo();
        t1.start();
        t2.start();*/
        /*//实现Runnable方式创建线程
        RunDemo d1 = new RunDemo();
        RunDemo d2 = new RunDemo();
        Thread t3 = new Thread(d1);
        Thread t4 = new Thread(d2);
        t3.start();
        t4.start();*/
        //上述方式的优化版本：
        //匿名内部类
        Thread t5 = new Thread() {
            @Override
            public void run() {
                System.out.println("匿名内部类创建线程");
            }
        };
        t5.start();
        //匿名对象
        new Thread(){
            @Override
            public void run() {
                System.out.println("匿名对象开启线程");
            }
        }.start();
        //匿名内部类实现Runnable接口
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("匿名内部实现类实现Runnable接口");
            }
        };
        Thread t6 = new Thread(runnable);
        t6.start();
        //匿名对象实现Runnable
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("匿名对象实现Runnable");
            }
        }).start();
    }
}